package com.book.controller;

import com.book.model.dto.BookAddDTO;
import com.book.model.dto.BookQueryDTO;
import com.book.model.entity.Books;
import com.book.service.BooksService;
import com.book.util.BaseResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 书本表 前端控制器
 * </p>
 *
 * @author auto
 * @since 2025-04-02 06:38:55
 */
@RestController
@RequestMapping("/book")
@Tag(name = "书本", description = "书本相关接口")
public class BooksController{

    @Autowired
    private BooksService booksService;

    @PostMapping("/list")
    @ApiOperation(value = "书本列表", notes = "书本列表")
    public BaseResult<?> getBookListByPage(@RequestBody BookQueryDTO bookQueryDTO) {
        return BaseResult.successResult(booksService.getBookListByPage(bookQueryDTO));
    }

    @GetMapping("")
    @ApiOperation(value = "书本列表", notes = "小程序搜索书本列表")
    public BaseResult<?> getBookListByWxParam(String msg) {
        return BaseResult.successResult(booksService.getBookListByWxParam(msg));
    }

    @GetMapping("/newFive")
    @ApiOperation(value = "书本列表", notes = "获取最新的5条数据")
    public BaseResult<?> getBookListNewFile() {
        return BaseResult.successResult(booksService.getBookListNewFile());
    }

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "书本列表", notes = "根据ID获取书本信息")
    public BaseResult<?> getBookById(@PathVariable("id") String id) {
        return BaseResult.successResult(booksService.getBookById(id));
    }

    @GetMapping("/publishOrPurchase/{publish}/{userId}")
    @ApiOperation(value = "获取我发布的或者购买的书本", notes = "获取我发布的或者购买的书本")
    public BaseResult<?> getPublishOrPurchase(@PathVariable("publish") boolean publish, @PathVariable("userId") String userId) {
        return BaseResult.successResult(booksService.getPublishOrPurchase(publish,userId));
    }

    @DeleteMapping("/{bookId}")
    @ApiOperation(value = "根据ID删除书本", notes = "根据ID删除书本")
    public BaseResult<?> deleteById(@PathVariable("bookId") String bookId) {
        return BaseResult.successResult(booksService.removeById(bookId));
    }

    @PostMapping("/order/{bookId}/{userId}")
    @ApiOperation(value = "购买")
    public BaseResult<?> createOrder(@PathVariable("bookId") String bookId, @PathVariable("userId") String userId) {
        return BaseResult.successResult(booksService.createOrderBook(bookId, userId));
    }

    @PostMapping("/cancel/{bookId}")
    @ApiOperation(value = "取消订单")
    public BaseResult<?> cancel(@PathVariable("bookId") String bookId) {
        return BaseResult.successResult(booksService.cancelOrderBook(bookId));
    }

    @PostMapping("/notice/{bookId}")
    @ApiOperation(value = "提送短信通知")
    public BaseResult<?> sendTelNotice(@PathVariable("bookId") String bookId) {
        return BaseResult.successResult(booksService.sendTelNotice(bookId));
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加书籍信息")
    public BaseResult<?> add(@RequestBody BookAddDTO book) {
        return BaseResult.successResult(booksService.userAddBook(book));
    }

    @PostMapping("/confirmBook/{bookId}")
    @ApiOperation(value = "确认收货")
    public BaseResult<?> confirmBook(@PathVariable("bookId") String bookId) {
        return BaseResult.successResult(booksService.confirmBook(bookId));
    }

    @PostMapping("/publishQuery")
    @ApiOperation(value = "查询发布的数据")
    public BaseResult<?> publishQuery(@RequestBody BookQueryDTO book) {
        return BaseResult.successResult(booksService.publishQuery(book));
    }

    @PostMapping("/reuse/{bookId}")
    @ApiOperation(value = "旧书回收")
    public BaseResult<?> reuse(@PathVariable("bookId") String bookId) {
        return BaseResult.successResult(booksService.reuse(bookId));
    }

    @PostMapping("/shelve/{bookId}/{newCondition}/{points}")
    @ApiOperation(value = "书籍上架")
    public BaseResult<?> shelve(@PathVariable("bookId") String bookId, @PathVariable("newCondition") Integer newCondition,@PathVariable("points") Integer points) {
        return BaseResult.successResult(booksService.shelve(bookId, newCondition,points));
    }

}
